package com.example.android427;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.ListFragment;

public class gerenziliaoActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gerenziliao);

       Button fanhui = (Button)findViewById(R.id.ziliaofh_bt1);
        fanhui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        Button tuichu=findViewById(R.id.tuichu_bt);
        tuichu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(gerenziliaoActivity.this,DengluActivity.class);
                startActivity(intent);
            }
        });

        ListView mListView = (ListView) findViewById(R.id.listview2);
        // 添加ListItem，设置事件响应
        mListView.setAdapter(new gerenziliaoActivity.DemoListAdapter());
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View v, int index,
                                    long arg3) {
                onListItemClick(index);
            }
        });
    }

    void onListItemClick(int index) {
        Intent intent = null;
        intent = new Intent(gerenziliaoActivity.this, demos[index].demoClass);
        this.startActivity(intent);
    }

    private static final gerenziliaoActivity.DemoInfo[] demos = {
            new gerenziliaoActivity.DemoInfo(R.string.demoa_title, ActivityDemo1.class),
            new gerenziliaoActivity.DemoInfo(R.string.demob_title, ActivityDemo2.class),
            new gerenziliaoActivity.DemoInfo(R.string.democ_title, ActivityDemo3.class),
            new gerenziliaoActivity.DemoInfo(R.string.demod_title, ActivityDemo4.class),
            new gerenziliaoActivity.DemoInfo(R.string.demoe_title, ActivityDemo5.class),

    };

    private class DemoListAdapter extends BaseAdapter {
        public DemoListAdapter() {
            super();
        }
        @Override
        public View getView(int index, View convertView, ViewGroup parent) {
            convertView = View.inflate(gerenziliaoActivity.this,
                    R.layout.demo_info_item2, null);
            TextView title2 = (TextView) convertView.findViewById(R.id.title2);
            //TextView desc = (TextView) convertView.findViewById(R.id.desc);
            title2.setText(demos[index].title2);
            //desc.setText(demos[index].desc);
            if (index >= 14) {
                title2.setTextColor(Color.YELLOW);
            }
            return convertView;
        }

        @Override
        public int getCount() {
            return demos.length;
        }

        @Override
        public Object getItem(int index) {
            return demos[index];
        }

        @Override
        public long getItemId(int id) {
            return id;
        }
    }

    private static class DemoInfo {
        private final int title2;
        //private final int desc;
        private final Class<? extends android.app.Activity> demoClass;

        public DemoInfo(int title,
                        Class<? extends android.app.Activity> demoClass) {
            this.title2 = title;
            //this.desc = desc;
            this.demoClass = demoClass;
        }
    }

}
